package com.java46.amqp;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;


/**
 * @ClassName MessageSender
 * @Description 定义消息发送者（生产者）
 * @Author Tigger Wu
 * @Date 2018/8/23
 * @Version 1.0
 **/
@Service
public class MessageSender {
    private AmqpTemplate amqpTemplate;

    private String routingKey;

    public AmqpTemplate getAmqpTemplate() {
        return amqpTemplate;
    }

    public void setAmqpTemplate(AmqpTemplate amqpTemplate) {
        this.amqpTemplate = amqpTemplate;
    }

    public String getRoutingKey() {
        return routingKey;
    }

    public void setRoutingKey(String routingKey) {
        this.routingKey = routingKey;
    }

    public void sendDataToQueue(Object obj) {
        amqpTemplate.convertAndSend(this.routingKey,obj );
    }
}
